//
//  CeoYouHuiXVC.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/18.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "TodoHttpManager.h"
#import "CeoYouHuiXVC.h"
#import "DouDetailsCell.h"
#import "CEOYouHuiVC.h"
#import "LXAlertView.h"
@interface CeoYouHuiXVC ()<UITableViewDelegate,UITableViewDataSource>

{
    NSString *str;
    NSString *str1;
    NSString *str2;
    NSString *str3;
    NSArray *_titleArr;
    
}
@property(nonatomic,strong)UITableView *tabView;
@property(nonatomic,strong)NSMutableDictionary *zonDic;
@property(nonatomic,strong)NSMutableArray *oneArr;
@property(nonatomic,strong)UIButton *agreeBtn;
@property(nonatomic,strong)UIButton *unAgreeBtn;



@end

@implementation CeoYouHuiXVC

-(void)viewWillAppear:(BOOL)animated
{
    //TODO:优惠政策详情
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDCeoYouHuiX:) name:TDCeoYouHuiX object:nil];
    [_manager userCeoYouHuiXWithID:_piID];
    
    
     //TODO:优惠政策审批
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDCeoYouHShenP:) name:TDCeoYouHShenP object:nil];
    
    
}
-(void)didTDCeoYouHuiX:(NSNotification *)notifi
{
    if (notifi.object != 0)
    {
        _zonDic = [notifi.object objectForKey:@"data"];
        
        str = [_zonDic objectForKey:@"time"];
        str1 = [_zonDic objectForKey:@"pay_way"];
        str2 = [_zonDic objectForKey:@"yh"];
        
        str3 = [_zonDic objectForKey:@"syfw"];
      
        _oneArr = [[NSMutableArray alloc] initWithObjects:str,str1,str2,str3, nil];
        
    
        [_tabView reloadData];
        
    }
}


//优惠政策审批
-(void)didTDCeoYouHShenP:(NSNotification *)noti
{
    if (noti.object != nil)
    {
        int status = [[noti.object objectForKey:@"status"] intValue];
        NSString *infoStr = [noti.object objectForKey:@"info"];
        if (status == 1)
        {
            [_manager MakeMyselfAlert:infoStr andIsNeedTitle:NO andShowTime:1.5];
            CEOYouHuiVC *youVC = [[CEOYouHuiVC alloc] init];
            [self.navigationController pushViewController:youVC animated:NO];
        }
        if (status == 2)
        {
            [_manager MakeMyselfAlert:infoStr andIsNeedTitle:NO andShowTime:1.5];
            CEOYouHuiVC *youVC = [[CEOYouHuiVC alloc] init];
            [self.navigationController pushViewController:youVC animated:NO];
        }
    }
    
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDCeoYouHuiX object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:TDCeoYouHShenP object:nil];
}




- (void)viewDidLoad {
    [super viewDidLoad];
 
    self.title = @"优惠政策审批";
    self.view.backgroundColor = BgColor;
    
    _zonDic = [NSMutableDictionary dictionary];
    _oneArr = [NSMutableArray array];
    _titleArr = [NSArray arrayWithObjects:@"有效期:",@"付款方式:",@"优惠额度:",@"适用范围:", nil];
    _manager = [TodoHttpManager sharedManager];
    _tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, 250) style:UITableViewStylePlain];
    _tabView.delegate = self;
    _tabView.dataSource = self;
    _tabView.backgroundColor = BgColor;
    _tabView.rowHeight = 40;
    _tabView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:_tabView];
    
    if ([_statueStr isEqualToString:@"1"])
    {
        [self setButtonUI];
    }
    
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    
    return _titleArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndent = @"CellB";
    
    
    DouDetailsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell ==nil)
    {
        cell = [[DouDetailsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndent];
        
        
    }
    
    if ([cell isKindOfClass:[DouDetailsCell class]])
    {
        if (_oneArr.count !=0)
        {
            
            NSString *str0 = (NSString *)_oneArr[indexPath.row];
            cell.secondLab.text = [NSString stringWithFormat:@"%@",str0];
            
            
        }
        
        
    }
    
    cell.firstLab.text = _titleArr[indexPath.row];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//取消点击
    return cell;
    
    
    
}

-(void)setButtonUI
{
    _agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _agreeBtn.frame = CGRectMake(15, 360, B_WIDTH-15*2, 40);
    _agreeBtn.backgroundColor = [UIColor orangeColor];
    _agreeBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    _agreeBtn.layer.cornerRadius = 5.0f;
    [_agreeBtn setTitle:@"同意执行" forState:0];
    [_agreeBtn addTarget:self action:@selector(agreeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_agreeBtn setTitleColor:[UIColor whiteColor] forState:0];
    [self.view addSubview:_agreeBtn];
    
    _unAgreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _unAgreeBtn.frame = CGRectMake(15, 420, B_WIDTH-15*2, 40);
    _unAgreeBtn.backgroundColor = [UIColor orangeColor];
    _unAgreeBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    _unAgreeBtn.layer.cornerRadius = 5.0f;
    [_unAgreeBtn setTitle:@"驳回审批" forState:0];
    [_unAgreeBtn setTitleColor:[UIColor whiteColor] forState:0];
     [_unAgreeBtn addTarget:self action:@selector(unAgreeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_unAgreeBtn];

    
}

-(void)agreeBtnClick:(UIButton *)btn
{
    
    LXAlertView *agreeView = [[LXAlertView alloc] initWithTitle:@"提示" message:@"同意执行?" cancelBtnTitle:@"取消" otherBtnTitle:@"确认" clickIndexBlock:^(NSInteger clickIndex) {
        
        if (clickIndex == 1)
        {
            
            NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
            [_manager userCeoYouHuiShenPiWithDid:_piID withUid:IDA withType:@"2"];
            [self.navigationController popViewControllerAnimated:NO];
        }
        
        
        
    }];
    [agreeView showLXAlertView];
    
    
    
   
}

-(void)unAgreeBtnClick:(UIButton *)btn
{
    
    
    LXAlertView *agreeView = [[LXAlertView alloc] initWithTitle:@"提示" message:@"驳回修改?" cancelBtnTitle:@"取消" otherBtnTitle:@"确认" clickIndexBlock:^(NSInteger clickIndex) {
        
        if (clickIndex == 1)
        {
            
            
            NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
            [_manager userCeoYouHuiShenPiWithDid:_piID withUid:IDA withType:@"3"];
            [self.navigationController popViewControllerAnimated:NO];
        }
        
        
        
    }];
    [agreeView showLXAlertView];
    
  
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
